/*
Copyright (C) 2015 Pieter Staal

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef RIVER_H
#define RIVER_H

#include <SFML/Graphics.hpp>

using namespace sf;

const Vector2i directions[9] { Vector2i(-1,-1),     // North West
                               Vector2i(0, -1),     // North
                               Vector2i(1, -1),     // North East
                               Vector2i(-1, 0),     // West
                               Vector2i(0,  0),     // -
                               Vector2i(1,  0),     // East
                               Vector2i(-1, 1),     // South West
                               Vector2i(0,  1),     // South
                               Vector2i(1,  1)};    // South East

struct RiverSettings
{
    bool *watermap;
    double *normalizedHeightmap;
    double *displayWatermap;
    Vector2i position;
    int riverCoordMod;
    int mapSize;
};

class River
{
    public:
        River(RiverSettings settings);
        Vector2i getPos() { return position; }
        void setPos(Vector2i p) { position = p; }
        void addDirection(char direction) { generatorPath.push_back(direction); }
        int flow();
        void complete();
        std::vector<char>* getGeneratorPath() { return &generatorPath; }
        std::vector<char>* getTotalPath() { return &totalPath; }
        void drawOnMap();
        int stepBack();
        bool hasBeenCompleted() { return completed; }
    protected:
    private:
        Vector2i position;
        Vector2i startPosition;
        std::vector<char> generatorPath;
        std::vector<char> totalPath;

        bool *watermap;
        double *normalizedHeightmap;
        double *displayWatermap;

        int riverCoordMod;
        int mapSize;
        int branches = 0;
        int length = 0;
        bool completed = false;
};

#endif // RIVER_H
